//-----------------Sonic CD Menu Control Script---------------//
//--------Scripted by Christian Whitehead 'The Taxman'--------//
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//
//------------------Only exist in WP7 Versions----------------//

// Aliases
#alias Object.Value0	:	Object.Timer	// Also used for fading
#alias Object[32].State	:	LEntry.State

// States
#alias 0	:	MENUCONTROL_SETUP
#alias 1	:	MENUCONTROL_FADEIN
#alias 2	:	MENUCONTROL_CONTROLS
#alias 3	:	MENUCONTROL_BLANK
#alias 4	:	MENUCONTROL_EXIT

// LEntry States
#alias 1	:	LENTRY_MOVE_RIGHT
#alias 4	:	LENTRY_MOVE_LEFT
#alias 7	:	LENTRY_MOVE_DOWN
#alias 10	:	LENTRY_MOVE_UP

// Presentation Stages
#alias 1	:	STAGE_P_MENU

// Soundtrack
#alias 0	:	OST_JP

// Global SFX
#alias 23	:	SFX_G_MENUBUTTON
#alias 27	:	SFX_G_SELECT

// Engine & Callbacks
#alias 3	:	CALLBACK_TATTACK_NOTIFY_EXIT


sub ObjectMain
	switch Object.State
	case MENUCONTROL_SETUP
		Object.State = MENUCONTROL_FADEIN
		Object.Timer = 384
		SetScreenFade(0, 0, 0, 255)
		PlayMusic(0)
		break

	case MENUCONTROL_FADEIN
		if Object.Timer > 0
			Object.Timer -= 8
			Object.Scale -= 4096
		else
			Object.State  = MENUCONTROL_CONTROLS
		end if
		SetScreenFade(0, 0, 0, Object.Timer)
		break

	case MENUCONTROL_CONTROLS
		if KeyPress[0].Left == true
			Object.State = MENUCONTROL_BLANK
			LEntry.State = LENTRY_MOVE_LEFT
			PlaySfx(SFX_G_MENUBUTTON, false) 
		end if

		if KeyPress[0].Right == true
			Object.State = MENUCONTROL_BLANK
			LEntry.State = LENTRY_MOVE_RIGHT
			PlaySfx(SFX_G_MENUBUTTON, false) 
		end if

		if KeyPress[0].Up == true
			Object.State = MENUCONTROL_BLANK
			LEntry.State = LENTRY_MOVE_UP
			PlaySfx(SFX_G_MENUBUTTON, false) 
		end if

		if KeyPress[0].Down == true
			Object.State = MENUCONTROL_BLANK
			LEntry.State = LENTRY_MOVE_DOWN
			PlaySfx(SFX_G_MENUBUTTON, false) 
		end if

		if KeyPress[0].ButtonB == true
			Object.State = MENUCONTROL_EXIT
			StopMusic()
			PlaySfx(SFX_G_SELECT, false)
		end if
		break

	case MENUCONTROL_BLANK
		break

	case MENUCONTROL_EXIT
		if Object.Timer < 384
			Object.Timer += 8
			Object.Scale += 4096
		else
			Stage.ListPos = STAGE_P_MENU
			LoadStage()
		end if
		SetScreenFade(0, 0, 0, Object.Timer)
		EngineCallback(CALLBACK_TATTACK_NOTIFY_EXIT)
		break

	end switch
end sub


sub ObjectStartup
		SetMusicTrack("JP/Credits.ogg", 0, 100512)
	Object[0].Type		= TypeName[Menu Control]
	Object[0].DrawOrder = 1
	Options.PhysicalControls = false
end sub


// ========================
// Editor Subs
// ========================

sub RSDKDraw
	DrawSprite(0)
end sub


sub RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)		// #0 - "Script" Icon

	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end sub
